package com.example.myproject.controller;

import com.example.myproject.database.primary.entity.User1Entity;
import com.example.myproject.database.primary.repository.UserRepositoryPrimary;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * controller 负责页面访问控制
 */
//@Controller
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserRepositoryPrimary userRepositoryPrimary;

    @RequestMapping(value = "/hello")
    public String index() {
        return "Hello Spring Boot 2.0!";
    }

    @RequestMapping(value = "/getUser", method = RequestMethod.GET)
    public User1Entity getUser(Long id) {
        User1Entity user1Entity = userRepositoryPrimary.findById(id);
        return user1Entity;
    }

    @RequestMapping(value = "/getUsers", method = RequestMethod.GET)
    public List<User1Entity> getUsers() {
        List<User1Entity> userEntityList = userRepositoryPrimary.findAll();
        return userEntityList;
    }
}